// pages/evaluate/evaluate.js
const api = require('../../utils/http.js');
const app = getApp();
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		note: '',
		satrArray_q: [1, 2, 3, 4, 5],
		satrArray_s: [1, 2, 3, 4, 5],
		satrArray_a: [1, 2, 3, 4, 5],
		starId_q: 0,
		starId_s: 0,
		starId_a: 0,
		src1: '../images/star_green.png',
		src2: '../images/star_grey.png',
		orderId: '',
		qishou_id: ''
	},
	getContent(e) {
		let note = e.detail.value;
		this.setData({
			note
		})
	},
	select(e) {
		let order = e.currentTarget.dataset.order
		if (order == 0) {
			this.data.starId_q = e.currentTarget.dataset.index;
			this.setData({
				starId_q: this.data.starId_q
			})
		} else if (order == 1) {
			this.data.starId_s = e.currentTarget.dataset.index;
			this.setData({
				starId_s: this.data.starId_s
			})
		} else if (order == 2) {
			this.data.starId_a = e.currentTarget.dataset.index;
			this.setData({
				starId_a: this.data.starId_a
			})
		}
	},
	submit() {
		console.log(this.data.note)
		console.log(this.data.starId_q, this.data.starId_s, this.data.starId_a)
		if (!this.data.note) {
			wx.showToast({
				title: `请输入您的评价`,
				icon: 'none'
			})
		} else {
			let uid = app.globalData.uid;
			api.fetchApi('procedure_t', {
				p: `R2009009|${this.data.note}|0|${this.data.orderId}|${this.data.qishou_id}|6001|${uid}|${this.data.starId_q}|${this.data.starId_q}|${this.data.starId_s}|${this.data.starId_a}`
			}).then(res => {
				const {
					code,
					results
				} = res.data
				if (code == 1) {
					wx.showToast({
						title: `提交成功`,
						icon: 'success',
						success: () => {
							setTimeout(() => {
								wx.navigateBack({

								})
							}, 1500)
						}
					})
				} else {
					wx.showToast({
						title: `${res.data.errorMsg}`,
						icon: 'none'
					})
				}
			})
		}
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		console.log(options);
		let orderId = options.orderId;
		let qishou_id = options.qishou_id;
		this.setData({
			orderId,
			qishou_id
		})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
